package com.innoking.docsys.workflow.controller;

import com.innoking.docsys.utils.JsonToOtherUtil;
import com.innoking.docsys.utils.OtherPojo;
import com.innoking.docsys.utils.ResultObjVO;
import com.innoking.docsys.workflow.componet.ActivitiAppointTask;
import com.innoking.docsys.workflow.module.WorkflowRunVo;
import com.innoking.docsys.workflow.service.WorkflowRunService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 描述:
 *
 * @author zyp
 * @description 工作流运行控制器
 * @create 2019-09-09 17:07
 */
@RestController
@RequestMapping("/workflowRun")
public class WorkflowRunController {

    Logger logger= LoggerFactory.getLogger(WorkflowRunController.class);

    @Autowired
    protected WorkflowRunService workflowRunService;

    @Autowired
    private ActivitiAppointTask activitiAppointTask;

    /**
     * @author:zyp
     * @description 根据执行的流程id，读取资源
     * @date: 2019/9/9 17:14
     * @return 
     */
    @PostMapping(value = "/loadByProcessInstance")
    public void loadByProcessInstance(@RequestBody String data, HttpServletResponse response){
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new WorkflowRunVo() );
        WorkflowRunVo workflowRunVo = (WorkflowRunVo)ob.getObj();
        workflowRunService.loadByProcessInstance(workflowRunVo,response);
    }

    /**
     * @author:zyp
     * @description 根据当前运行的工作流程获取 流程中第一个执行的taskUser是否为指派关系
     * @date: 2019/9/10 10:23
     * @return
     */
    @PostMapping(value = "/selectFirstTaskUser")
    public ResultObjVO selectFirstTaskUser(@RequestBody String data){
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new WorkflowRunVo() );
        WorkflowRunVo workflowRunVo = (WorkflowRunVo)ob.getObj();
        ResultObjVO resultObjVO = workflowRunService.selectFirstTaskUser(workflowRunVo);
        return resultObjVO;
    }

    /**
     * @author:zyp
     * @description 获取下一个任务的审核人
     * @date: 2019/9/10 10:51
     * @return 
     */
    @PostMapping(value = "/selectNextTaskUser")
    public ResultObjVO selectNextTaskUser(@RequestBody String data){
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new WorkflowRunVo() );
        WorkflowRunVo workflowRunVo = (WorkflowRunVo)ob.getObj();
        ResultObjVO result = activitiAppointTask.appointTask(workflowRunVo.getTaskId());
        return result;
    }
}